package com.serviceImpl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Service;

import com.bean.User;
import com.mapper.UserMapper;
import com.service.UserService;

/**
 * @author author : 张鹏
 * @date createTime：2018年1月10日 下午3:28:49
 * @Description: 该类的功能描述
 */
@Service
public class UserServiceImpl implements UserService {
	@Resource
	private UserMapper userMappser;

	@Override
	public User login(User user) {
		return userMappser.login(user);
	}

	@Override
	public List<User> getAllCook() {
		// TODO Auto-generated method stub
		return userMappser.selectCookAll();
	}
	
	@Override
	public List<User> getAllUser() {
		// TODO Auto-generated method stub
		return userMappser.selectAll();
	}

	@Override
	public int deleteUser(int userId) {
		// TODO Auto-generated method stub
		return userMappser.deleteUser(userId);
	}

	@Override
	public List<User> getAllSupplier() {
		// TODO Auto-generated method stub
		return userMappser.selectSupplierAll();
	}

	@Override
	public User getUserByPrimaryKey(int userId) {
		// TODO Auto-generated method stub
		return userMappser.selectByPrimaryKey(userId);
	}

	@Override
	public int createNewUser(User user) {
		// TODO Auto-generated method stub
		return userMappser.insert(user);
	}

	@Override
	public int updateUser(User user) {
		if (user.getPassword()==null) {
			return userMappser.updateByPrimaryKeyNoPassword(user);
		}else {
			user.setPassword(DigestUtils.md5Hex(user.getPassword()));
			return userMappser.updateByPrimaryKey(user);
		}
	}
}
